#ifndef LEVEL_H
#define LEVEL_H

#include "obstacle.h"
#include "song.h"

#include <vector>
#include <list>

namespace Lib3D {
	class Graphics;
}

class ObstaclePosition {
public:
	float x, y, z;
	float width, height, depth;
};

class Level { 
public:
	enum State {
		PLAYING,
		GAMEOVER
	};

	Level(Song & song);
	~Level();

	void handleEvents();
	void startTimer();
	void update();
	bool shouldRun();

	int getTotalTime();
	unsigned int getElapsedTime();
	Song & getSong();
	ObstaclePosition getObstaclePosition(Obstacle * obstacle);

	Level::State getState() { return state; }
	int getLife() { return life; }
	int getLifeMax() { return lifeMax; }
	int getHitWindow() { return hitWindow; }
	void collision(Obstacle * obstacle);

	friend class Lib3D::Graphics;

private:
	Song & song;
	Song::Iterator songIterator;
	int levelPosition;
	const int displayedDuration; // in milliseconds
	bool running;
	unsigned int previousTime, timeOffset;

	Level::State state;
	int life, lifeIncrement, lifeDecrement, lifeMax;
	const int hitWindow;
	std::list<std::pair<Obstacle*,bool> > currentObstacles; // false: not yet collided, true: already collided
};

#endif // LEVEL_H
